'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 建筑
 * @author sundbcn@gmail.com (sun debing)
 */

var buildConf = require('../../config/buildConf');
var attrFromAtkType = require('./attrFromAtkType');
var weaknessAttr = require('./weaknessAttr');
var resistanceAttr = require('./resistanceAttr');
var constantUtil = require('../../util/constantUtil');

/**
 * 获得建筑的战斗属性
 * @param  {[type]} hero_type    [description]
 * @param  {[type]} hero_lv      [description]
 * @return {[type]}              [description]
 */
exports.getAttr = function (build_type, build_lv, build_ratio) {
    build_ratio = build_ratio || 0;
    var build_type_conf = buildConf.getBuildTypeConf(build_type);
    var build_lv_conf = buildConf.getBuildLvConf(build_type, build_lv);
    if (!build_lv_conf) {
        console.error('build can not found:' + build_type + ',lv:' + build_lv);
        return {};
    }
    var atk_type_attr = {};
    if (build_type_conf.atk_type > 0) {
        atk_type_attr = attrFromAtkType.getAttr(build_type_conf.atk_type, build_lv_conf.atk, build_ratio);
    }
    return {
        min_atk: atk_type_attr.min_atk,
        max_atk: atk_type_attr.max_atk,
        fire_damage: atk_type_attr.fire_damage,
        ice_damage: atk_type_attr.ice_damage,
        light_damage: atk_type_attr.light_damage,
        city_damage: atk_type_attr.city_damage,
        hp: build_lv_conf.hp,
        hit: 100,
        crit: 0,
        uncrit: 9999,
        crit_addition: constantUtil.value('crit_addition'),
        dodge: 0,
        aoe_radius: build_type_conf.aoe_radius,
        atk_interval: build_type_conf.atk_interval,
        atk_range: build_type_conf.atk_range,
        weakness_list: weaknessAttr.getAttr(build_type_conf.weakness_type),
        resistance_list: resistanceAttr.getAttr(build_type_conf.resistance_type)
    };
};
